package com.ws.service;

import com.ws.bean.Note;
import com.ws.dao.EmployeeDao;
import com.ws.dao.NoteDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoteService {

    @Autowired
    private NoteDao noteDao;

    @Autowired
    private EmployeeDao employeeDao;



    public void addNote(Note note) {
        noteDao.addNote(note);
    }

    public int lines(int position, int status, int eid, int did) {
        List<Integer> ids = null;
        if (status == -1) { //员工和经理用来查询自己请假记录的条数
            return noteDao.lines(null, status, eid);
        } else {
            if (position == 0) { //获取所有经理的 eid
                ids = employeeDao.findEidByPosition(1);
            } else { //获取所有员工的 eid
                ids = employeeDao.findIdsByDid(did);
            }

            return noteDao.lines(ids, status, eid);
        }
    }



    public List<Note> findNoteByPage(int page, int size, int position, int eid, int did, int status) {
        page = (page - 1) * size;
        List<Note> notes = null;
        if (position == 0) {//老板的
            List<Integer> ids = employeeDao.findEidByPosition(1);
            notes = noteDao.findNoteByPage(page, size, ids, eid, status);
        } else if (position == 1) {//经理的
            if (eid == -1) {//待审批/已审批
                List<Integer> ids = employeeDao.findIdsByDid(did);
                notes = noteDao.findNoteByPage(page, size, ids, eid, status);
            } else { //查看自己的请假记录
                notes = noteDao.findNoteByPage(page, size, null, eid, status);
            }
        } else {//员工的
            notes = noteDao.findNoteByPage(page, size, null, eid, status);
        }

        return notes;
    }

    public void updateStatus(int nid, int status) {
        noteDao.updateStatus(nid, status);
    }
}
